#include "Input.h"


bool Input::keyD[512];
bool Input::keyH[512];
int Input::mouseXV = 0;
int Input::mouseYV = 0;
bool Input::mouseH[10];
bool Input::mouseD[10];




bool keyHit(int k)
{
	return Input().keyHit(k);
}

bool keyDown(int k)
{
	return Input().keyDown(k);
}

int mouseX()
{
	return Input().mouseX();
}

int mouseY()
{
	return Input().mouseY();
}


Input::Input()
{
}

Input::~Input()
{
}

bool Input::keyHit(int key)
{
	return keyH[key];
}

bool Input::keyDown(int key)
{
	return keyD[key];
}
int Input::mouseX()
{
	return mouseXV;
}
int Input::mouseY()
{
	return mouseYV;
}
bool Input::mouseHit(int button)
{
	return mouseH[button];
}

bool Input::mouseDown(int button)
{
	return mouseD[button];
}

void Input::detectInput()
{
	for(int x=0; x<512; x++)
		keyH[x] = 0;
	for(int x=0; x<10; x++)
		mouseH[x] = 0;

	SDL_Event event;
	if (SDL_PollEvent(&event)) {
		switch (event.type)
		{
			case SDL_VIDEORESIZE:
				//winWidth = event.resize.w;
				//winHeight = event.resize.h;
				//SDL_SetVideoMode( winWidth, winHeight, 16, SDL_OPENGL | SDL_RESIZABLE );
				//glViewport(0, 0, winWidth, winHeight);
				break;

			case SDL_QUIT:
				exit(0);
				break;
			case SDL_KEYUP:
				keyD[event.key.keysym.sym] = 0;
				break;
			case SDL_KEYDOWN:
				keyD[event.key.keysym.sym] = 1;
				keyH[event.key.keysym.sym] = 1;
				break;
			case SDL_MOUSEMOTION:
				mouseXV = event.motion.x;
				mouseYV = event.motion.y;
				break;
			case SDL_MOUSEBUTTONUP:
				mouseD[event.button.button] = 0;
				break;
			case SDL_MOUSEBUTTONDOWN:
				mouseD[event.button.button]=1;
				mouseH[event.button.button]=1;
				break;
		}
	}

}